<script setup>
import {ref} from "vue";
import request5151 from "../../../utils/request5151.js";
import {ElMessage} from "element-plus";
//loading
const loading = ref(true)
//搜索数据
const searchData = ref({
  sNumber: '',
  sname: "",
  buildingNumber: '',
  dormitoryNumber: '',
})
//重置
const reset = () => {
  searchData.value = {
    sNumber: '',
    sname: "",
    buildingNumber: '',
    dormitoryNumber: '',
  }
}
//分页相关
let pageNum = 1
let pageSize = 9
const total = ref(0)
const handleSizeChange = (val) => {
  pageSize = val
  getInRoomInfo()
}
const handleCurrentChange = (val) => {
  pageNum = val
  getInRoomInfo()
}
// 宿舍信息
const inRoomInfoData = ref()
// 获取宿舍信息
const getInRoomInfo = () => {
  request5151({
    url: '/dormitoryallocation/getAllDormitoryPage',
    method: 'get',
    params: {
      pageNumber: pageNum,
      pageSize: pageSize,
      sNumber: searchData.value.sNumber ? searchData.value.sNumber : null,
      sname: searchData.value.sname ? searchData.value.sname : null,
      buildingNumber: searchData.value.buildingNumber ? searchData.value.buildingNumber : null,
      dormitoryNumber: searchData.value.dormitoryNumber ? searchData.value.dormitoryNumber : null,
    }
  }).then((res) => {
    inRoomInfoData.value = res.data.data.records
    total.value = res.data.data.total
    loading.value = false
  }).catch(() => {
    ElMessage.error('请求失败')
    loading.value = false
  })
}
getInRoomInfo()
</script>

<template>
  <div class="myInRoomAll">
    <!--面包屑-->
    <el-breadcrumb separator="/" style="margin-bottom: 20px;">
      <el-breadcrumb-item><b>迎新信息管理</b></el-breadcrumb-item>
      <el-breadcrumb-item>学生入住信息</el-breadcrumb-item>
    </el-breadcrumb>
    <!--搜索-->
    <el-form :inline="true" :model="searchData" class="demo-form-inline">
      <el-form-item label="学号">
        <el-input v-model="searchData.sNumber" placeholder="输入学号"/>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="searchData.sname" placeholder="输入姓名"/>
      </el-form-item>
      <el-form-item label="楼号">
        <el-select
            v-model="searchData.buildingNumber"
            placeholder="选择楼号"
            clearable
            style="width: 120px;"
        >
          <el-option label="1号楼" value="1"/>
          <el-option label="2号楼" value="2"/>
          <el-option label="3号楼" value="3"/>
          <el-option label="4号楼" value="4"/>
        </el-select>
      </el-form-item>
      <el-button type="danger" @click="reset" style="margin-bottom: 20px;">重置</el-button>
      <el-button type="success" @click="getInRoomInfo" style="margin-bottom: 20px;">查询</el-button>
    </el-form>
    <!--数据-->
    <el-card>
      <el-table :data="inRoomInfoData" style="width: 100%" border="border" v-loading="loading"
               empty-text="暂无数据" element-loading-text="加载中">
        <el-table-column prop="snumber" label="学号" width="160"/>
        <el-table-column prop="sname" label="姓名" width="120"/>
        <el-table-column prop="buildingNumber" label="楼号" width="140">
          <template #default="scope">
            <el-tag type="success">{{ scope.row.buildingNumber }}号楼</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="dormitoryNumber" label="宿舍号" width="140">
          <template #default="scope">
            <el-tag type="warning">{{ scope.row.dormitoryNumber }}宿舍</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="bedNumber" label="床位号" width="140">
          <template #default="scope">
            <el-tag type="warning">{{ scope.row.bedNumber }}号床</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="location" label="宿舍楼位置" width="220"/>
      </el-table>
    </el-card>
    <!--分页-->
    <el-pagination background layout="prev,sizes, pager, next"
                   :page-sizes="[6,9]"
                   :total="total"
                   :page-size="pageSize"
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"

    />
  </div>
</template>

<style scoped>

</style>
